<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------


// 动态路由
use think\Route;

Route::get('home', 'index/index/index');
Route::post('ppp', 'index/index/ppp');

Route::rule('ooxx', 'index/index/index');
Route::any('xxoo', 'index/index/ppp');

// 闭包定义
Route::get('hehe', function () {
    return '呵呵哒';
});

// 规则的路由参数
// 无参
// Route::get('user', 'index/index/user');
// 必传参数
// Route::get('user/:id', 'index/index/user');
// 可选参数
// Route::get('user/[:id]', 'index/index/user');
// 匹配参数
// Route::get('user/[:id]$', 'index/index/user');

// 路由参数
// 用户列表
Route::get('userlist', 'admin/user/index', ['ext' => 'html|shtml']);


// 变量规则
// http://tp5.com/index/blog/index/id/55.html
// http://tp5.com/index/blog/read/name/anna.html
// http://tp5.com/index/blog/article/year/2017/month/09.html

// 按照指定的规则去分配变量,越容易匹配的越往后放.
// YEAR/MONTH:
// Route::get('blog/:year/:month','index/blog/article',['method'=>'get'],['year'=>'\d{4}','month'=>'\d{2}']);
// // ID:  http://tp5.com/blog/66
// Route::get('blog/:id','index/blog/index',['method'=>'get'],['id'=>'\d+']);
// // NAME:
// Route::get('blog/:name','index/blog/read',['method'=>'get'],['name'=>'\w+']);


Route::group('blog', [
    ':year/:month' => [
        'index/blog/article',
        ['method' => 'get'],
        [
            'year' => '\d{4}',
            'month' => '\d{2}'
        ]
    ],
    ':id' => [
        'index/blog/index',
        ['method' => 'get'],
        ['id' => '\d+']
    ],
    ':name' => [
        'index/blog/read',
        ['method' => 'get'],
        ['name' => '\w+']
    ]
]);

// 生成URL
Route::get('url', 'index/index/url');


// 资源控制器的路由  7条路由
// Route::resource('users', 'rest/User');






// 静态路由
return [
    '__pattern__' => [
        'name' => '\w+',
    ],
    '[hello]' => [
        ':id' => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
        ':name' => ['index/hello', ['method' => 'post']],
    ],

];
